const db = require('../db');
const theatersCrawler = require('./theatersCrawler');
const saveTheaters = require('./saveTheaters');
const {writeFileAsync} = require('../utils/tool_')
const crawlerData = async () => {
    try {
        //连接数据库
        await db;
        //爬取数据
        const data = await theatersCrawler();
        //将爬取的数据保存在数据库中
        await saveTheaters(data);
        return data  
    } catch (error) {
        console.log(error,'<<<<<<')
        //爬取数据
        const data = await theatersCrawler();
        // 没数据库 保存到本地
        await writeFileAsync(data,'theaters.txt')
        return data
    }
}
module.exports = crawlerData